package com.guguskins.back.controller;


import com.guguskins.back.entity.GuEggLevel;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuEggLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-05-19
 */
@RestController
@RequestMapping("/eggLevel")
public class GuEggLevelController {

    @Autowired
    private GuEggLevelService eggLevelService;

    @GetMapping("/back/list")
    public ResultVo backList() {
        List<GuEggLevel> eggLevels = eggLevelService.list();
        return ResultVo.success(ObjectUtils.isEmpty(eggLevels) ? new ArrayList<>() : eggLevels);
    }

    @PostMapping("/back/update")
    public ResultVo updateEggLevels(@RequestBody @Validated  GuEggLevel guEggLevel) {
        eggLevelService.updateById(guEggLevel);
        return ResultVo.success();
    }
    @GetMapping("/back/findById")
    public ResultVo findById(@RequestParam(value = "id",required = false)Integer id)
    {
        return ResultVo.success(eggLevelService.getById(id),"查找成功");
    }

}
